<div class="editcate_top">
    <h2>Sửa tin tức</h2>
    <a href="javascript:void(0)" onclick ="$('#light_adct').hide();$('#fade_adct').hide()"><img src="<?php echo img_link('close.png', 'admin'); ?>" class="png" /></a>
</div>

<div id="div_message"></div>

<form enctype="multipart/form-data" method="post" action="<?php echo action_link('edit/'.$articles->id); ?>" id="articles_form">
<div class="editcate_ct">
	<div class="btarticle">
    	<input type="button" value="Cancel" class="btn" onclick="$('#light_adct').hide();$('#fade_adct').hide();" />
        <input type="submit" value="Save & Continute" class="btn" />
    </div>
	<div class="boxadd">
    	<ul class="linect">
    		<li>
                <span class="left"><b>Tiêu đề<font color="red">(*)</font> :</b></span>
                <span class="right"><input type="text" name="txt_title" value="<?php echo $articles->title;?>" style="width:100%; margin:0;" /></span>
            </li>
            
            <?php if(count($images) > 0){ ?>
            <?php foreach($images as $i => $image): ?>
            <li>
                <span class="left">Ảnh minh họa</span>
                <span class="right">                	
                	<input type="file" name="images[<?php echo $i; ?>]" value="" /><br />                	
                	<input type="hidden" name="images_id[<?php echo $i; ?>]" value="<?php echo $image->id; ?>" />
                	<p><img src="<?php echo site_url($image->img_path); ?>" /></p>
                </span>
            </li>
            <?php endforeach; ?>
            <?php } else { ?>
            <?php for($i = 0; $i < 1; $i++): ?>
            <li>
                <span class="left">Ảnh minh họa</span>
                <span class="right">                	                	
                	<input type="file" name="images[]" value="" /><br />                	
                </span>
            </li>
            <?php endfor; ?>	
            <?php }?>
           <li>
                <span class="left_title"><b>Sản phẩm liên quan <font color="red">(Nhập ID sản phẩm, phân cách nhau bởi dấu phẩy. VD: 1,2,4,6)</font> :</b></span>                
            </li>
            <li>
            	<?php $id_products = $this->articles_model->get_id_products_with_articles($articles->id);?>
            	<?php
            		$str_id = array(); 
            		foreach($id_products as $m => $n)
            		{
            			$str_id[] = $n->id_product;
            		}
            		$str_id_product = implode(",", $str_id);
            	?>
            	
            	<input type="text" name="txt_id_product" value="<?php echo isset($str_id_product) && $str_id_product != null ? $str_id_product : "";?>" style="width:67%; margin:0;margin-left: 78px;" />
            </li>
            <li>
            	<span class="left">Mô tả</span>
            	<span class="right">
                	<textarea id="txt_desc" name="txt_desc" style="width:82%; height:150px;"><?php echo $articles->description;?></textarea>
                </span>            	
            </li>    
            <li>
                <b>Nội dung:<font color="red">(*)</font></b>
            </li>
            <li>
                <span class="right">
                	<textarea id="txt_content" name="txt_content"  style="width:100%; height:200px;"><?php echo $articles->contents;?></textarea>
                </span>
                <script type="text/javascript">
				$(function() {				    				    
				    $('#news_form').iframer({
				        onComplete: function(msg){
				        	if(msg == 'yes') {
				        		$('#light_adct').hide();$('#fade_adct').hide();
				        		var reload_link = '<?php echo action_link('index?cat_id='); ?>'+$('[name=cat_id]').val();
				        		if(window.location.href == reload_link) {
				        			load_content('list', window.location.href, true);
				        		}
				        		else {
				        			window.location.href = reload_link;	
				        		}
				        	}
				        	else show_error('div_message', msg)
				        }
				    });
				    
					if(CKEDITOR.instances['txt_content']) {						
						CKEDITOR.remove(CKEDITOR.instances['txt_content']);
					}
					CKEDITOR.config.width = 504;
				    CKEDITOR.config.height = 400;
					CKEDITOR.replace('txt_content',{
				    	toolbar :
				    		[['Source','Maximize','-','Format','Font','FontSize'],'/',
				    		 ['PasteText','PasteFromWord'],
					         ['TextColor','BGColor','-','Bold','Italic','Underline'],
					         ['NumberedList','BulletedList'],'/',
					         ['Outdent','Indent','Blockquote'],
					         ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
					         ['Image','Table','-', 'Link', 'Unlink' ]]
					});
				})
				</script>                
            </li> 
            
       		<li>
                <span class="left"><b>Tác giả:</b></span>
                <span class="right"><input type="text" name="txt_author" value="<?php echo $articles->author;?>" style="width:100%; margin:0;" /></span>
            </li> 
            <li>
                <span class="left"><b>Nguồn bài viết:</b></span>
                <span class="right"><input type="text" name="txt_source" value="<?php echo $articles->source;?>" style="width:100%; margin:0;" /></span>
            </li>  
            <li>
                <span class="left">&nbsp;</span>
                <span class="right">
                	<input id="cck_News_works" <?php echo ($articles->news_works == 'yes') ? 'checked="checked"' : '';?> type="checkbox"  name="cck_News_works"  style="margin:0;" /><b>Tin công trình</b>
                </span>
            </li>    
       		<li>
                <span class="left">&nbsp;</span>
                <span class="right">
                	<input id="cck_news_recruitment" <?php echo ($articles->news_recruitment == 'yes') ? 'checked="checked"' : '';?> type="checkbox"  name="cck_news_recruitment"  style="margin:0;" /><b>Tin tuyển dụng</b>
                </span>
            </li>  
       		<li>
       			<span class="left"><b>Trạng thái:</b></span>
       			 <span class="right">
                    <select style="width:130px;" name="status" id="status">
                      <option <?php echo ($articles->status == 'yes') ? 'selected="selected"' : '';?> value="yes" style="color: blue;">Kích hoạt</option>
                      <option <?php echo ($articles->status == 'no') ? 'selected="selected"' : '';?> value="no" style="color: red;">Chưa kích hoạt</option>
                    </select>
                </span>
       		</li>
       		
        </ul>
    </div>
    <div class="btarticle">
    	<input type="button" value="Cancel" class="btn" onclick="$('#light_adct').hide();$('#fade_adct').hide();" />
        <input type="submit" value="Save & Continute" class="btn" />
    </div>
</div>
</form>
<script>
$('#articles_form').iframer({
    onComplete: function(msg){
    	if(msg == 'yes') {
    		$('#light_adct').hide();$('#fade_adct').hide();
            load_content('row_<?php echo $articles->id; ?>', admin_url+'articles/load_row/<?php echo $articles->id; ?>');
            $('.linecate2').has('#row_<?php echo $articles->id; ?>').css('background-color', '#FFFFE0');
    	}
    	else show_error('div_message', msg)
    }
});
</script>